package com.pinxixi.order.service;

import com.pinxixi.framework.domain.cart.ItemCart;
import com.pinxixi.framework.domain.order.Order;
import com.pinxixi.framework.domain.order.OrderEntity;
import com.pinxixi.framework.model.response.CommonCode;
import com.pinxixi.framework.model.response.QueryResponseResult;
import com.pinxixi.order.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;

    public QueryResponseResult createOrder(OrderEntity orderEntity) {
        Order order = orderEntity.getOrderInfo();
        orderMapper.createOrder(order);
        List<ItemCart> orderItem = orderEntity.getOrderItem();
        for (ItemCart item:orderItem) {
            orderMapper.createOrderItem(item,order.getOrderId());
        }
        return new QueryResponseResult(CommonCode.SUCCESS,order.getOrderId()+"");
    }

    public QueryResponseResult getOrder(String id) {
        Order order = orderMapper.findOne(id);
        return new QueryResponseResult(CommonCode.SUCCESS,order);
    }
}
